package server

import (
	"../../deps/lessgo/utilx"
	"../state"
	"../store"
)

func MemberPeerCast(req ActionRequst, addr string) {

	peerid := req.Get("peerid")
	if !utilx.ArrayContain(peerid, state.PeerIds) {
		return
	}

	led, ok := state.Peers[peerid]
	if !ok {
		return
	}

	if state.Leader.Id != led.Id {

		state.Leader = led

	} else {

		if state.Leader.Addr != led.Addr {
			state.Leader.Addr = led.Addr
		}
		if state.Leader.Port != led.Port {
			state.Leader.Port = led.Port
		}
		if state.Leader.Proto != led.Proto {
			state.Leader.Proto = led.Proto
		}
	}

	store.Cmd("SETEX", "sys:ol:"+peerid, 16, req.Get("content"))
}
